/**
 * 
 */
package com.postek.coyote.postekwifi;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

import com.postek.cdf.CDFPTKAndroid;
import com.postek.coyote.postekwifi.bean.LabelBean;
import com.postek.coyote.postekwifi.bean.PDFBean;

import java.util.ArrayList;

/**
 * @author yrwang
 * 
 */
public class PrintPDFActivity extends AppCompatActivity {

	private CDFPTKAndroid cdf = MainActivity.cdf;
	private ArrayList<LabelBean> labelBeans = MainActivity.labelBeans;

	private Button btnPrint = null;
	private Button btnCancel = null;

	private EditText et_PDF1 = null;
	private EditText et_PDF2 = null;
	private Spinner sp_PDF3 = null;
	private Spinner sp_PDF4 = null;
	private EditText et_PDF5 = null;
	private EditText et_PDF6 = null;
	private EditText et_PDF7 = null;
	private EditText et_PDF8 = null;
	private Spinner sp_PDF9 = null;
	private Spinner sp_PDF10 = null;
	private EditText et_PDFS = null;
	private EditText et_print_number=null;
	private EditText et_print_cpnumber=null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.print_pdf);

		btnPrint = (Button) findViewById(R.id.btn_printPDF_print);
		btnCancel = (Button) findViewById(R.id.btn_printPDF_cancel);

		et_PDF1 = (EditText) findViewById(R.id.et_print_PDF1);
		et_PDF2 = (EditText) findViewById(R.id.et_print_PDF2);
		sp_PDF3 = (Spinner) findViewById(R.id.sp_print_PDF3);
		sp_PDF4 = (Spinner) findViewById(R.id.sp_print_PDF4);
		et_PDF5 = (EditText) findViewById(R.id.et_print_PDF5);
		et_PDF6 = (EditText) findViewById(R.id.et_print_PDF6);
		et_PDF7 = (EditText) findViewById(R.id.et_print_PDF7);
		et_PDF8 = (EditText) findViewById(R.id.et_print_PDF8);
		sp_PDF9 = (Spinner) findViewById(R.id.sp_print_PDF9);
		sp_PDF10 = (Spinner) findViewById(R.id.sp_print_PDF10);
		et_PDFS = (EditText) findViewById(R.id.et_print_PDFS);
		et_print_number= (EditText) findViewById(R.id.et_print_number);
		et_print_cpnumber= (EditText) findViewById(R.id.et_print_cpnumber);

		btnCancel.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});

		btnPrint.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				int iPDF1 = 0;
				int iPDF2 = 0;
				int iPDF3 = sp_PDF3.getSelectedItemPosition();
				int iPDF4 = sp_PDF4.getSelectedItemPosition();
				int iPDF5 = 0;
				int iPDF6 = 0;
				int iPDF7 = 0;
				int iPDF8 = 0;
				int iPDF9 = sp_PDF9.getSelectedItemPosition();
				int iPDF10 = sp_PDF10.getSelectedItemPosition();
				String iPDFS = et_PDFS.getText().toString();
				int number=Integer.parseInt(et_print_number.getText().toString());
				int cpnumber=Integer.parseInt(et_print_cpnumber.getText().toString());


				if (!("".equals(et_PDF1.getText().toString()))) {
					iPDF1 = Integer.parseInt(et_PDF1.getText().toString());
				}

				if (!("".equals(et_PDF2.getText().toString()))) {
					iPDF2 = Integer.parseInt(et_PDF2.getText().toString());
				}

				if (!("".equals(et_PDF5.getText().toString()))) {
					iPDF5 = Integer.parseInt(et_PDF5.getText().toString());
				}

				if (!("".equals(et_PDF6.getText().toString()))) {
					iPDF6 = Integer.parseInt(et_PDF6.getText().toString());
				}

				if (!("".equals(et_PDF7.getText().toString()))) {
					iPDF7 = Integer.parseInt(et_PDF7.getText().toString());
				}

				if (!("".equals(et_PDF8.getText().toString()))) {
					iPDF8 = Integer.parseInt(et_PDF8.getText().toString());
				}

				int nReturn = cdf.PTK_DrawBar2D_Pdf417(iPDF1, iPDF2, 0, 0,
						iPDF3, iPDF4, iPDF5, iPDF6, iPDF7, iPDF8, iPDF9,
						iPDF10, iPDFS);

				if (nReturn == 0) {
					PDFBean bean = new PDFBean(iPDF1, iPDF2, iPDF3, iPDF4, iPDF5, iPDF6, iPDF7, iPDF8, iPDF9, iPDF10, iPDFS);
					labelBeans.add(bean);
					Toast.makeText(PrintPDFActivity.this, R.string.setting_success,
							Toast.LENGTH_SHORT).show();
				   cdf.PTK_PrintLabel(number,cpnumber);
				} else {
					Toast.makeText(PrintPDFActivity.this,  R.string.setting_fail,
							Toast.LENGTH_SHORT).show();
				}
			}
		});

	}

}
